<?php
showtipss($touclicklang['tcmsg0012'],'tips1',true,$touclicklang['tipsTitle4']);

$report=array();

$page= isset($_GET['page'])?$_GET['page']:1; 
$pagesize = 15;
$pagelen = 3;

$sign = $_GET['signType'];
if(submitcheck('statReportDetailSubmit')) {
	$sign = $_POST['signType']?$_POST['signType']:$_GET['signType']; 
}

if($sign){
	$data= array(
			"b" => $touclickB,
			"z" => $touclickZ,
			"v" => $touclickV,
			"d" => $touclickD,
			"pf" => $touclickPF,
			"srf" => $sign,
			'cs' => $touclickCS,
			'sl' => $pagesize * ($page -1 ),
			'ps' => $pagesize,
	);
	
	$resRep = touclick_request("http://api.touclick.com/statreport.touclick", $data, 80);
	if($resRep['content'] == "alert"){
		cpmsg("{$touclicklang['alert']}", "", 'error');
	}elseif($resRep['content'] == "wait"){
		cpmsg("{$touclicklang['wait']}", "", 'error');
	}elseif($resRep['content'] == "live"){
		cpmsg("{$touclicklang['live']}", "action=plugins&cp=$cp&pmod=activate&operation=$operation&do=$do", 'error');
	}elseif($resRep['content'] == "vip"){
		cpmsg("{$touclicklang['vip']}");
	}
	$report = $tcJSON->decode($resRep['content'], true);
}
$phpfile = "admin.php?action=plugins&cp=$cp&pmod=report&operation=$operation&do=$do&signType=$sign";
$pageNum = $report[count];
$getpageinfo = page($page, $pageNum, $phpfile, $pagesize, $pagelen);

showformheader("plugins&cp=$cp&pmod=report&operation=$operation&do=$do","",'statReportDetailForm','post');
showtableheader();;
$selectorFlag = ($sign !=0 && $sign == 1003)?"selected":"";
echo "<tr><td width='100px' style='width:100px;font-weight: 700;'>{$touclicklang['selectcondition']}</td><td><select id ='signType' name = 'signType'>".'<option value="1002">'.$touclicklang['todaydetail'].'</option><option value="1003" '." {$selectorFlag}>{$touclicklang['yesterdaydetail']}</option></select></td></tr>";
echo "<tr><td colspan=2 ><input id='statReportDetailSubmit' class='btn' type='submit'  value='{$touclicklang['submit']}' title='{$touclicklang['submitTip']}' name='statReportDetailSubmit' /></td>";
showtablefooter();
showformfooter();
require_once (DISCUZ_ROOT.'./source/function/function_misc.php');

if($sign != 0 && $sign == 1002){
	showtableheader("{$touclicklang['todaydetail']}");
	echo "<tr class='header'><th>{$touclicklang['username']}</th><th>{$touclicklang['request']}</th><th>{$touclicklang['success']}</th><th>{$touclicklang['fail']}</th><th>{$touclicklang['complete']}</th><th>{$touclicklang['userip']}</th><th>{$touclicklang['tcmsg0019']}</th></tr>";
	foreach($report[mlist] as $detailModel){
		$uname = "-";
		if($detailModel[username] != null){
			$uurl = $_G['siteurl']."home.php?mod=space&uid=".$detailModel[userid];
			$uname = "<a href='{$uurl}' target='_blank'>".base64_decode($detailModel[username])."</a>";
		}
		$iploca =substr(convertip($detailModel[ip]), 1);
		echo "<tr class='hover'><td>{$uname}</td><td>{$detailModel[get]}</td><td>{$detailModel[succes]}</td><td>{$detailModel[fail]}</td><td>{$detailModel[complete]}</td><td>{$detailModel[ip]}</td><td>{$iploca}</td></tr>";
	}
	echo "<tr><td colspan=7 align=right>".$getpageinfo['pagecode']."</td></tr>";
	showtablefooter();
}elseif($sign != 0 && $sign == 1003){

	showtableheader("{$touclicklang['yesterdaydetail']}");
	echo "<tr class='header'><th>{$touclicklang['username']}</th><th>{$touclicklang['request']}</th><th>{$touclicklang['success']}</th><th>{$touclicklang['fail']}</th><th>{$touclicklang['complete']}</th><th>{$touclicklang['userip']}</th><th>{$touclicklang['tcmsg0019']}</th></tr>";
	foreach($report[mlist] as $detailModel){
		$uname = "-";
		if($detailModel[username] != null){
			$uurl = $_G['siteurl']."home.php?mod=space&uid=".$detailModel[userid];
			$uname = "<a href='{$uurl}' target='_blank'>".base64_decode($detailModel[username])."</a>";
		}
		$iploca = substr(convertip($detailModel[ip]), 1);
		echo "<tr class='hover'><td>{$uname}</td><td>{$detailModel[get]}</td><td>{$detailModel[succes]}</td><td>{$detailModel[fail]}</td><td>{$detailModel[complete]}</td><td>{$detailModel[ip]}</td><td>{$iploca}</td></tr>";
	}
	echo "<tr><td colspan=7 align=right>".$getpageinfo['pagecode']."</td></tr>";
	showtablefooter();
}